import React, { Component } from 'react'
import { Form, Input, Button, message } from 'antd';
import { _userRegisty } from "../Api/api"
export default class Registry extends Component {
    render() {
        const Demo = () => {
            const onFinish = async (values) => {
                console.log('Success:', values);
                let { data } = await _userRegisty(values);
                console.log(data);
                if (data.code === 1) {
                    message.success(data.msg).then(setTimeout(() => {
                        this.props.history.push("/login")
                    }, 3600));
                } else {
                    message.error(data.msg);   // 全局错误提示
                }
            };

            const onFinishFailed = (errorInfo) => {
                console.log('Failed:', errorInfo);
            };
            return (
                <Form
                    name="basic"
                    labelCol={{
                        span: 4,
                    }}
                    wrapperCol={{
                        span: 20,
                    }}
                    initialValues={{
                        remember: true,
                    }}
                    onFinish={onFinish}
                    onFinishFailed={onFinishFailed}
                >
                    <Form.Item
                        label="用户名"
                        name="username"

                        rules={[
                            {
                                required: true,
                                message: '用户名不能为空!',
                            },
                        ]}
                    >
                        <Input placeholder="请输入用户名" />
                    </Form.Item>

                    <Form.Item
                        label="密码"
                        name="password"
                        rules={[
                            {
                                required: true,
                                message: '密码不能为空!',
                            },
                        ]}
                    >
                        <Input.Password placeholder="请输入密码" />
                    </Form.Item>

                    <Form.Item
                        wrapperCol={{
                            offset: 2,
                            span: 22,
                        }}
                    >
                        <Button block type="primary" htmlType="submit">
                            注册
                        </Button>
                    </Form.Item>
                </Form>
            );
        }
        return (
            <div className="form">
                <div className="back"><span onClick={() => this.props.history.go(-1)}>返回</span></div>
                <div className="registy">

                    <div><Demo /></div>
                </div>

            </div>
        )
    }
}
